import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

enum TaskType { send, todo }


class GetWorkbenchLogic extends GetxController
    with GetTickerProviderStateMixin {
  late TabController tabController;

 var sendRefreshController = RefreshController(initialRefresh: false);
 var todoRefreshController = RefreshController(initialRefresh: false);


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    tabController = TabController(length: 2, vsync: this);
    loadInitialData();
  }

  @override
  onClose() {
    tabController.dispose();
    super.onClose();

    sendRefreshController.dispose();
    todoRefreshController.dispose();

  }

  var sendItems = <String>[].obs; // 使用 GetX 响应式列表
  var todoItems = <String>[].obs; // 使用 GetX 响应式列表

  // 加载初始数据
  void loadInitialData() {
    sendItems.assignAll(List.generate(15, (index) => "海外制单进口审批 $index"));
    todoItems.assignAll(List.generate(15, (index) => "海外制单进口审批 $index"));
  }

  // 下拉刷新
  void onSendRefresh() async {
    await Future.delayed(Duration(seconds: 2));
    sendItems.assignAll(List.generate(15, (index) => "(新)  海外制单进口审批 $index"));
    sendRefreshController.refreshCompleted();
  }

  // 上拉加载更多
  void onSendLoadMore() async {
    await Future.delayed(Duration(seconds: 2));
    sendItems.addAll(
        List.generate(5, (index) => "(更多)  海外制单进口审批 ${sendItems.length + index}"));
    sendRefreshController.loadComplete();
  }


  // 下拉刷新
  void onTodoRefresh() async {
    await Future.delayed(Duration(seconds: 2));
    todoItems.assignAll(List.generate(15, (index) => "(新)  海外制单进口审批 $index"));
    todoRefreshController.refreshCompleted();
  }

  // 上拉加载更多
  void onTodoLoadMore() async {
    await Future.delayed(Duration(seconds: 2));
    todoItems.addAll(
        List.generate(5, (index) => "(更多)  海外制单进口审批 ${todoItems.length + index}"));
    todoRefreshController.loadComplete();
  }
}
